/*
 * Copyright (c) 2025 Li Auto Inc. and its affiliates
 * Licensed under the Apache License, Version 2.0(the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*!*********************************************************************************************************************
 * @file        comm_cfg.h
 * @brief       ComM 配置头文件
 * @details     主要包含 ComM 动态配置项
 * @date        {{get_generation_time()}}
 * @toolversion {{get_vcos_version()}}
 **********************************************************************************************************************/

#ifndef COMM_CFG_H
#define COMM_CFG_H

#include "comm_types.h"

#ifdef __cplusplus
extern "C"
{
#endif

/* Global Macro Definition */
#define COMM_DEV_ERROR_DETECT                     ({{ gen_switch_macro(dict_config["ActiveEcuC"]["ComM"]["ComMGeneral"]["ComMDevErrorDetect"]["Value"]) }})
#define COMM_MODE_LIMITATION_ENABLED              ({{ gen_switch_macro(dict_config["ActiveEcuC"]["ComM"]["ComMGeneral"]["ComMModeLimitationEnabled"]["Value"]) }})
#define COMM_FULL_COM_MIN_DURATION_TIME         ({{ get_time_ms(dict_config["ActiveEcuC"]["ComM"]["ComMGeneral"]["ComMTMinFullComModeDuration"]["Value"]) }}u)

{% set channels = dict_config["ActiveEcuC"]["ComM"]["ComMConfigSet"]["ComMChannels"].items() %}
/* 不同通信频道/网络 */
{%- for channel_name, channel_value in channels %}
{%- if channel_name != "Tag" %}
#define COMM_NETWORK_HANDLE_{{ channel_name }}          ({{ channel_value["ComMChannelId"]["Value"] }}u)          ///< {{channel_name}}的网络管理
#define ComMConf_ComMChannel_{{ channel_name }}          ({{ channel_value["ComMChannelId"]["Value"] }}u)         ///< ComM管理{{channel_name}}通道
{%- endif %}
{%- endfor %}

#define COMM_CHANNEL_COUNT                         ({{ channels|length-1 }}u)             ///< ComM 通道数量

{%- if "ComMUsers" in dict_config["ActiveEcuC"]["ComM"]["ComMConfigSet"] %}
{% set users = dict_config["ActiveEcuC"]["ComM"]["ComMConfigSet"]["ComMUsers"].items() %}
/*!*********************************************************************************************************************
 * @brief       不同通信用户
 **********************************************************************************************************************/
{%- for user_name, user_value in users %}
{%- if user_name != "Tag" %}
#define COMM_USER_HANDLE_{{ user_name }}           ((ComM_UserHandleType){{ user_value["ComMUserIdentifier"]["Value"] }}u) ///< {{user_name}}的handle
#define ComMConf_ComMUser_{{ user_name }}          ({{ user_value["ComMUserIdentifier"]["Value"] }}u)                      ///< ComM管理{{ user_name }}用户
{%- endif %}
{%- endfor %}

#define COMM_USER_COUNT                           ({{ users|length-1 }}u)             ///< ComM 用户数量
{%- else %}
#define COMM_USER_COUNT                           (0u)                               ///< ComM 用户数量
{%- endif %}

#define COMM_START_SEC_CONST 
#include "comm_memmap.h"
extern CONST(comm_config_type, COMM_CONST) comm_config;
#define  COMM_STOP_SEC_CONST
#include "comm_memmap.h"

#ifdef __cplusplus
}
#endif

#endif /* COMM_CFG_H */
